// 统计时间的修饰器
export const Time = function (tag) {
	return function handleDescriptor(target, key, descriptor) {
		const fn = descriptor.value;
		const fnName = tag ? tag : fn.name;
		return {
			...descriptor,
			value() {
				let time = new Date().getTime();
				console.log(`[${fnName}]START-----`);
				try {
					return fn.apply(this, arguments);
				} finally {
					let runTime = new Date().getTime() - time;
					console.log(`[${fnName}]END----->` + runTime);
				}
			}
		};
	};
};

export const TimeAsync = function (tag) {
	return function handleDescriptor(target, key, descriptor) {
		const fn = descriptor.value;
		const fnName = tag ? tag : fn.name;
		return {
			...descriptor,
			async value() {
				let time = new Date().getTime();
				console.log(`[${fnName}]START-----`);
				try {
					return await fn.apply(this, arguments);
				} finally {
					let runTime = new Date().getTime() - time;
					console.log(`[${fnName}]END----->` + runTime);
				}
			}
		};
	};
};
